#include <stdio.h>

typedef struct{
	int numitor;
	int numarator;
}Rational;
Rational suma(Rational, Rational );
Rational produs(Rational,Rational);
Rational diff(Rational,Rational);
Rational q(Rational, Rational);
Rational simplifica(Rational rez);
int main()
{
	Rational f1,f2;
	f1.numarator=2;
	f1.numitor=2;
	f2.numitor=2;
	f2.numarator=2;
	printf("%d|%d",suma(f1,f2).numarator,suma(f1,f2).numitor);	
	printf("\n%d|%d",produs(f1,f2).numarator,produs(f1,f2).numitor);	
	Rational d=diff(f1,f2);
	printf("%d|%d",d.numarator,d.numitor);
	Rational c=q(f1,f2);
	printf("%d|%d",c.numarator,c.numitor);
	Rational si=simplifica(f1);
	Rational sl=simplifica(f2);
	printf("\n%d|%d\n%d|%d",si.numarator,si.numitor,sl.numarator,sl.numitor);

	return 0;
}
Rational suma(Rational f1, Rational f2)
{
	Rational rez;
	rez.numarator=f1.numarator*f2.numitor+f1.numitor*f2.numarator;
	rez.numitor=f1.numitor*f2.numitor;
	return rez;
}
Rational produs(Rational f1,Rational f2)
{
	Rational rez;
	rez.numarator=f1.numarator*f2.numarator;
	rez.numitor=f1.numitor*f2.numitor;
	return rez;
}
Rational diff(Rational f1,Rational f2)
{
	f2.numarator=-f2.numarator;
	return suma(f1,f2);
}
Rational q(Rational f1,Rational f2)
{
	Rational t;
	t.numarator=f2.numitor;
	t.numitor=f2.numarator;
	return produs(f1,t);
}
int cmmdc(int a, int b)
{
    if((!a) || (!b)) return a+b;
    if(a>b) return cmmdc(a%b,b);
    return cmmdc(a,b%a);
}

Rational simplifica(Rational si)
{
	Rational rez;
	int x;
	x=cmmdc(si.numitor,si.numarator);
	rez.numitor=si.numitor/x;
	rez.numarator=si.numarator/x;
	return rez;
}


